package com.explorati.interview.interview.chapterThree;

public class BasicAndReferenceType {

	public static class Student {
		public String name;
		public int age;

		public Student(String name, int age) {
			this.name = name;
			this.age = age;
		}

		public void refChf() {
			this.name = "wangwu";
			this.age = 23;
		}

		@Override
		public String toString() {
			return "Student [name=" + name + ", age=" + age + "]";
		}

	}

	public static void main(String[] args) {
		Student stu1 = new Student("zhangsan", 20);
		Student stu2 = stu1;
		stu2.refChf();
		// Student [name=wangwu, age=23]
		System.out.println(stu1);

		// 基本类型是值传递，a改变i不改变
		int i = 10;
		int a = i;
		System.out.println("i = " + i);
		System.out.println("a = " + a);
		a = 5;
		System.out.println("a = " + a);
		System.out.println("i = " + i);
	}
	/*
	 * 本测试中，stu2与stu1指向同一内存地址，所以stu2修改时stu1的内容也被修改
	 * Student [name=wangwu, age=23]
	a = 10
	a = 5
	i = 10
	 */
}
